package com.cyan.tools.handler;

import com.cyan.tools.bean.BodyResponse;
import com.google.gson.Gson;

import java.io.IOException;

import retrofit2.HttpException;

/**
 * Created by pc on 2017/3/6.
 */

public class ErrorHandler {
    public static BodyResponse handle(Throwable throwable) {
        if (throwable instanceof HttpException) {
            HttpException error = (HttpException) throwable;
            try {
                return new Gson().fromJson(error.response().errorBody().string(),
                        BodyResponse.class);
            } catch (Exception e) {
                e.printStackTrace();
            }
        } else {
            throwable.printStackTrace();
        }
        return null;
    }
}
